#include "UserActivity.hpp"
#include "GameContext.hpp"
#include "Action.hpp"

#define MSG_NOTHING_HAPPENED "nothing happened..."
#define MSG_NO_MATCHING_KEY "you don't have matching key..."
#define MSG_FOUND_MATCHING_KEY "you used a key"

namespace backpack {

MessageAction g_actionNothingHappened(MSG_NOTHING_HAPPENED);
MessageAction g_actionNoMatchingKey(MSG_NO_MATCHING_KEY);
MessageAction g_actionFoundMatchingKey(MSG_FOUND_MATCHING_KEY);



void TouchActivity::let(ActivityContext &context) const {
  if (!m_rTouchPoint.get().isVisible()) {
    return;
  }
  if (!m_rTouchPoint.get().isEnabled()) {
    context.enqueueAction(g_actionNothingHappened);
    return;
  }
  context.enqueueAction(m_rTouchPoint.get().getAction());
}


void UnlockActivity::let(ActivityContext &context) const {
  if (!m_rUnlockPoint.get().isVisible()) {
    return;
  }

  if (!context.inventoryContains(std::cref(m_rUnlockPoint.get().getKey()))) {
    context.enqueueAction(g_actionNoMatchingKey);
    return;
  }

  context.enqueueAction(g_actionFoundMatchingKey);
  if (!m_rUnlockPoint.get().isEnabled()) {
    context.enqueueAction(g_actionNothingHappened);
    return;
  }

  context.enqueueAction(m_rUnlockPoint.get().getAction());
}


void WayPointActivity::let(ActivityContext &context) const {
  if (!m_rWayPoint.get().isVisible()) {
    return;
  }
  if (!m_rWayPoint.get().isEnabled()) {
    context.enqueueAction(MessageAction(m_rWayPoint.get().getLockedString()));
    return;
  }
  context.enqueueAction(MoveAction(m_rWayPoint.get().getTargetNode()));
}


void QuitActivity::let(ActivityContext &context) const {
  context.enqueueAction(EndAction());
}



} // namespace backpack

